package rickyGame.ui.pack
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	
	import rickyGame.controller.Controller;
	
//	import ricky.ui.Hand;

	/**
	 *格子的容器</br>
	 * 需求，每个格子可以对应一个快捷键。
	 * 每个格子的物品点击然后选择目标使用。
	 * author:pu
	 * data:2011.3.8 
	 */
	public class Vessel extends Sprite
	{
		
		public function Vessel(template:Class=null)
		{
			super();
			if(template==null)
			//	template=IconResource.vesselBg;
			_skin=new template();
			this.addChildAt(_skin,0);
//				
			this.addEventListener(MouseEvent.MOUSE_OVER,onOver);
//			this.addEventListener(MouseEvent.MOUSE_OVER,InputController.instance.onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT,onOut);
//			this.addEventListener(MouseEvent.MOUSE_OUT,InputController.instance.onMouseOut);
			this.addEventListener(MouseEvent.MOUSE_DOWN,Controller.instance.onMouseDown);
			this.addEventListener(MouseEvent.CLICK,Controller.instance.mouseClick);
		}
		
		override public function set width(value:Number):void
		{
			super.width=value;
			_skin.width=value;
		}
		
		override public function set height(value:Number):void
		{
			super.height=value;
			_skin.height=value;
		}
		
		/**
		 * 
		 */
		override public function addChild(child:DisplayObject):DisplayObject
		{
			if(this.numChildren==1)
				return super.addChild(child);
			return null;
		}
		
		/**
		 * 添加格子物品
		 */
		public function addGrid(grid:Grid):DisplayObject
		{
			if(this.numChildren==1)
				return super.addChild(grid);
			return null;
		}
		
		private function onOver(e:MouseEvent):void
		{
			if(this.isfull)
				this.filters=[new GlowFilter(0xff0000)];
			else				
				this.filters=[new GlowFilter(0xffff00)];
		}
		
		private function onOut(e:MouseEvent):void
		{
			this.filters=[];
		}

		/**
		 * 是否格子里放了东西
		 */
		public function get isfull():Boolean
		{
			return this.numChildren>1;
		}
		
		//private
		
		private var _skin:DisplayObject;
	}
}